using System;
using System.Net;

namespace MimeCloud.Foundations.Net
{
    /// <summary>
    /// Used because the .NET Framework WebClient class does not handle cookies
    /// Credit: http://couldbedone.blogspot.com/2007/08/webclient-handling-cookies.html
    /// </summary>
    public class WebClient : System.Net.WebClient
    {
        private CookieContainer _cookieContainer = new CookieContainer();

        public CookieContainer CookieContainer
        {
            get
            {
                return _cookieContainer;
            }
        }

        protected override WebRequest GetWebRequest(Uri address)
        {
            WebRequest request = base.GetWebRequest(address);
            if (request is HttpWebRequest)
            {
                (request as HttpWebRequest).CookieContainer = _cookieContainer;
            }
            return request;
        }

    }
}

